//index.js
//获取应用实例
const app = getApp();
Page({
  data: {
  	phone:'',
  	password:''
  },
  onLoad (options) {
  		this.setData({
	      phone: options.phone
	    })
  },
  handlLogin (phone,password) {
  	var phone = this.data.phone
  	var password = this.data.password
  	var url = app.globalData.url.loginPhone;
  	wx.request({
      url: url,
      data: {
        "cfrom":app.globalData.cfrom,
        "phone": phone,
        "password":password
      },
      method: "GET",
      success(res) {
        let data = res.data
        if(data.status == "_0000"){
          var datas = data.data;
          var userId = datas.id,userPass = password,userPhone = phone;
          app.globalData.userId = userId
          app.globalData.userPass = userPass
          app.globalData.userPhone = userPhone
        	wx.showToast({title:"登录成功",icon:'none'})
        	setTimeout(function(){
            wx.redirectTo({
              url:'../index/index'
            })
        	},2000)
        }else{
            wx.showToast({title:data.message,icon:'none'})
        }
  	},
      fail(res) {
        console.log(res.statusCode)
      }
    })
  },
	goForgetPassword(){
		var phone = this.data.phone
		wx.navigateTo({url:'../findPassword/index?phone='+phone})
	},
 	filterBlank(e){
	    var str = e.detail.value
	    if(str.indexOf(" ") >= 0){
	    	wx.showToast({title:"密码不应该含有空格",icon:'none'})
	    }
	    str = str.replace(/\s+/g,'');
	    this.setData({
	      password: str
	    })
	}
})
